//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.Diagnostics;
using System.Diagnostics.Contracts;
using System.Reflection;

namespace OpenLS.Spreadsheet.Formats.Biff.Records
{
    internal static class BiffRecordFactory
    {
#if DEBUG
        private static bool tested = false;
        public static void Test()
        {
            return;
            if (tested)
                return;
            foreach (
                BiffRecordType type in
                    Enumerable.Select(typeof (BiffRecordType).GetFields(BindingFlags.Static | BindingFlags.GetField | BindingFlags.NonPublic | BindingFlags.Public), f => f.GetValue(null)))
            {
                object o = NewRecord(type);
                if (!o.GetType().Name.EndsWith("Record"))
                    Debug.WriteLine(o.GetType().Name);
               Contract.Assert(o.GetType().Name.EndsWith("Record"));
            }
            tested = true;
        
    }


#endif
        public static BiffRecord NewRecord(BiffRecordType type)
        {
            Contract.Ensures(Contract.Result<BiffRecord>() != null);
            Contract.Ensures(Contract.Result<BiffRecord>().RecordType == type);
            switch (type)
            {
                case BiffRecordType.Format:
                    return new FormatRecord();
                case BiffRecordType.Selection:
                    return new SelectionRecord();
                case BiffRecordType.BoundSheet8:
                    return new BoundSheetRecord();
                case BiffRecordType.Continue:
                    return new ContinueRecord();
                case BiffRecordType.ColInfo:
                    return new ColumnInfoRecord();
                case BiffRecordType.Lbl:
                    return new LblRecord();
                case BiffRecordType.Font:
                    return new FontRecord();
                case BiffRecordType.Blank:
                    return new BlankRecord();
                case BiffRecordType.XF:
                    return new XFRecord();
                case BiffRecordType.MergeCells:
                    return new MergedCellsRecord();
                case BiffRecordType.BoolErr:
                    return new BoolOrErrorRecord();
                case BiffRecordType.Formula:
                    return new FormulaRecord();
                case BiffRecordType.SST:
                    return new SstRecord();
                case BiffRecordType.LabelSst:
                    return new LabelSstRecord();
                case BiffRecordType.RK:
                    return new RkRecord();
                case BiffRecordType.Number:
                    return new NumberRecord();
                case BiffRecordType.MulRk:
                    return new MulRKRecord();
                case BiffRecordType.MulBlank:
                    return new MulBlankRecord();
                case BiffRecordType.EOF:
                    return new EofRecord();
                case BiffRecordType.BOF:
                    return new BofRecord();
                case BiffRecordType.InterfaceHdr:
                    return new InterfaceHdrRecord();
                case BiffRecordType.Mms:
                    return new MMSRecord();
                case BiffRecordType.InterfaceEnd:
                    return new InterfaceEndRecord();
                case BiffRecordType.Row:
                    return new RowRecord();
                case BiffRecordType.ShrFmla:
              //\\  case BiffRecordType.ShrFmla_:
                    return new SharedFormulaRecord();
                case BiffRecordType.ExternName:
                    return new ExternNameRecord();

                case BiffRecordType.RefreshAll:
                    return new RefreshAllRecord();
                case BiffRecordType.CalcMode:
                    return new CalcModeRecord();
                case BiffRecordType.String:
                    return new StringRecord();
                case BiffRecordType.Window2:
                    return new Window2Record();
                case BiffRecordType.Scl:
                    return new SCLRecord();
                case BiffRecordType.ExtSST:
                    return new ExtSstRecord();
                case BiffRecordType.Style:
                    return new BiffStyleRecord();
                case BiffRecordType.Palette:
                    return new PaletteRecord();
                case BiffRecordType.ExternSheet:
                    return new ExternSheetRecord();
                    //\\  return new ExternSheetRecord();
                case BiffRecordType.SupBook:
                    return new SupBookRecord();
                case BiffRecordType.Array:
                    return new ArrayRecord();


                case BiffRecordType.Password:
                    return new PasswordRecord();
                case BiffRecordType.FilePass:
                    return new FilePasswordRecord();


                case BiffRecordType.WriteAccess:
                    return new WriteAccessRecord();
                case BiffRecordType.DSF:
                    return new DsfRecord();
                case BiffRecordType.Excel9File:
                    return new Excel9FileRecord();
                case BiffRecordType.RRTabId:
                    return new RrTabIdRecord();
                case BiffRecordType.BuiltInFnGroupCount:
                    return new BuiltInFnGroupCountRecord();
                case BiffRecordType.WinProtect:
                    return new WindowProtectRecord();
                case BiffRecordType.Protect:
                    return new ProtectRecord();
                case BiffRecordType.Window1:
                    return new Window1Record();
                case BiffRecordType.Backup:
                    return new BackupRecord();
                case BiffRecordType.HideObj:
                    return new HideObjRecord();
                case BiffRecordType.Date1904:
                    return new Date1904Record();
                case BiffRecordType.CalcPrecision:
                    return new CalcPrecisionRecord();
                case BiffRecordType.BookBool:
                    return new BookBoolRecord();
                case BiffRecordType.CodePage:
                    return new CodePageRecord();
                case BiffRecordType.CodeName:
                    return new CodeNameRecord();
                case BiffRecordType.Prot4Rev:
                    return new Prot4RevRecord();
                case BiffRecordType.Prot4RevPass:
                    return new Prot4RevpassRecord();

                case BiffRecordType.XFCRC:
                    return new XfcrcRecord();
                case BiffRecordType.XFExt:
                    return new XfExtRecord();

                case BiffRecordType.StyleExt:
                    return new StyleExtRecord();

                case BiffRecordType.TableStyle:
                    return new TableStyleRecord();
                case BiffRecordType.TableStyleElement:
                    return new TableStyleElementRecord();
                case BiffRecordType.TableStyles:
                    return new TableStylesRecord();
                case BiffRecordType.UsesELFs:
                    return new UseselfsRecord();
                case BiffRecordType.MTRSettings:
                    return new MtrSettingsRecord();
                case BiffRecordType.ForceFullCalculation:
                    return new ForcefullCalculationRecord();

                case BiffRecordType.Country:
                    return new CountryRecord();
                case BiffRecordType.Guts:
                    return new GutsRecord();

                case BiffRecordType.Index:
                    return new IndexRecord();
                case BiffRecordType.BookExt:
                    return new BookExtRecord();

                case BiffRecordType.Theme:
                    return new ThemeRecord();
                case BiffRecordType.CompressPictures:
                    return new CompressPicturesRecord();
                case BiffRecordType.CalcCount:
                    return new CalcCountRecord();

                case BiffRecordType.CalcRefMode:
                    return new CalcRefModeRecord();

                case BiffRecordType.CalcIter:
                    return new CalcIterRecord();
                case BiffRecordType.CalcDelta:
                    return new CalcDeltaRecord();
                case BiffRecordType.CalcSaveRecalc:
                    return new CalcSaveRecalcRecord();
                case BiffRecordType.GridSet:
                    return new GridSetRecord();
                case BiffRecordType.WsBool:
                    return new WsBoolRecord();

                case BiffRecordType.Header:
                    return new HeaderRecord();
                case BiffRecordType.Footer:
                    return new FooterRecord();
                case BiffRecordType.HCenter:
                    return new HCenterRecord();
                case BiffRecordType.VCenter:
                    return new VCenterRecord();
                case BiffRecordType.LeftMargin:
                    return new LeftMarginRecord();
                case BiffRecordType.RightMargin:
                    return new RightMarginRecord();
                case BiffRecordType.BottomMargin:
                    return new BottomMarginRecord();
                case BiffRecordType.DBCell:
                    return new DbCellRecord();
                case BiffRecordType.TopMargin:
                    return new TopMarginRecord();
                case BiffRecordType.Dimensions:
                    return new DimensionsRecord();


                case BiffRecordType.FeatHdr:
                    return new FeatHdrRecord();
                case BiffRecordType.PLV:
                    return new Plv12Record();
                case BiffRecordType.Plv2:
                    return new PlvRecord();
                case BiffRecordType.DefColWidth:
                    return new DefColWidthRecord();
                case BiffRecordType.HeaderFooter:
                    return new HeaderFooterRecord();
                case BiffRecordType.Setup:
                    return new SetupRecord();
                case BiffRecordType.DefaultRowHeight:
                    return new DefaultRowHeightRecord();
                case BiffRecordType.PrintGrid:
                    return new PrintGridRecord();
                case BiffRecordType.PrintRowCol:
                    return new PrintRowColRecord();
                case BiffRecordType.Compat12:
                    return new Compat12Record();
                case BiffRecordType.RecalcId:
                    return new RecalcIdRecord();
                case BiffRecordType.ObProj:
                    return new ObProjRecord();
                case BiffRecordType.ObNoMacros:
                    return new ObNoMacrosRecord();
                case BiffRecordType.GUIDTypeLib:
                    return new GuidTypeLibRecord();
                case BiffRecordType.Pls:
                    return new PlsRecord();
                case BiffRecordType.DxGCol:
                    return new DxGColRecord();


                    //////////////////////////


                case BiffRecordType.MsoDrawingGroup: return new  MsoDrawingGroupRecord();
                case BiffRecordType.MsoDrawing: return new  MsoDrawingRecord();
                case BiffRecordType.Sort: return new  SortRecord();
                case BiffRecordType.FilterMode: return new  FilterModeRecord();
                case BiffRecordType.AutoFilter: return new  AutoFilterRecord();
                case BiffRecordType.AutoFilterInfo: return new  AutoFilterInfoRecord();
                case BiffRecordType.Obj: return new  ObjRecord();
                case BiffRecordType.Pane: return new  PaneRecord();
                    // case BiffRecordType.Addin:

                case BiffRecordType.Dv: return new  DvRecord();
                case BiffRecordType.Feat: return new  FeatRecord();
                case BiffRecordType.FnGrp12: return new  FnGrp12Record();
                case BiffRecordType.Label: return new  LabelRecord();
                case BiffRecordType.List12: return new  List12Record();
                case BiffRecordType.MsoDrawingSelection: return new  MsoDrawingSelectionRecord();
                case BiffRecordType.Note: return new  NoteRecord();
                case BiffRecordType.ObjProtect: return new  ObjProtectRecord();
                case BiffRecordType.Qsi: return new  QsiRecord();
                case BiffRecordType.Qsif: return new  QsifRecord();
                case BiffRecordType.Qsir: return new  QsirRecord();
                case BiffRecordType.SheetExt: return new  SheetExtRecord();
                case BiffRecordType.Sxvd: return new  SxvdRecord();
                case BiffRecordType.SXVDEx: return new  SXVDExRecord();
                case BiffRecordType.SXVDTEx: return new  SXVDTExRecord();
                case BiffRecordType.SXVI: return new  SXVIRecord();
                case BiffRecordType.SxView: return new  SxViewRecord();
                case BiffRecordType.SXViewEx: return new  SXViewExRecord();
                case BiffRecordType.Table: return new  TableRecord();
                case BiffRecordType.Template: return new  TemplateRecord();
                case BiffRecordType.Uncalced: return new  UncalcedRecord();
                case BiffRecordType.BCUsrs: return new  BCUsrsRecord();
                case BiffRecordType.BigName: return new  BigNameRecord();
                case BiffRecordType.BkHim: return new  BkHimRecord();
                case BiffRecordType.BopPopCustom: return new  BopPopCustomRecord();
                case BiffRecordType.CatLab: return new  CatLabRecord();
                case BiffRecordType.CbUsr: return new  CbUsrRecord();
                case BiffRecordType.ChartFrtInfo: return new  ChartFrtInfoRecord();
                case BiffRecordType.ClrtClient: return new  ClrtClientRecord();
                case BiffRecordType.ContinueBigName: return new  ContinueBigNameRecord();
                case BiffRecordType.CrtLayout12: return new  CrtLayout12Record();
                case BiffRecordType.CrtLayout12A: return new  CrtLayout12ARecord();
                case BiffRecordType.CrtLink: return new  CrtLinkRecord();
                case BiffRecordType.CrtMlFrt: return new  CrtMlFrtRecord();
                case BiffRecordType.CrtMlFrtContinue: return new  CrtMlFrtContinueRecord();
                case BiffRecordType.CUsr: return new  CUsrRecord();
                case BiffRecordType.Dat: return new  DatRecord();
                case BiffRecordType.EndBlock: return new  EndBlockRecord();
                case BiffRecordType.EndObject: return new  EndObjectRecord();
                case BiffRecordType.EntExU2: return new  EntExU2Record();
                case BiffRecordType.Fbi: return new  FbiRecord();
                case BiffRecordType.Fbi2: return new  Fbi2Record();
                case BiffRecordType.FileLock: return new  FileLockRecord();
                case BiffRecordType.FrtFontList: return new  FrtFontListRecord();
                case BiffRecordType.FrtWrapper: return new  FrtWrapperRecord();
                case BiffRecordType.Intl: return new  IntlRecord();
                case BiffRecordType.LegendException: return new  LegendExceptionRecord();
                case BiffRecordType.Lel: return new  LelRecord();
                case BiffRecordType.LRng: return new  LRngRecord();
                case BiffRecordType.PhoneticInfo: return new  PhoneticInfoRecord();
                case BiffRecordType.PivotChartBits: return new  PivotChartBitsRecord();
                case BiffRecordType.PrintSize: return new  PrintSizeRecord();
                case BiffRecordType.RichTextStream: return new  RichTextStreamRecord();
                case BiffRecordType.RRAutoFmt: return new  RRAutoFmtRecord();
                case BiffRecordType.RRDChgCell: return new  RRDChgCellRecord();
                case BiffRecordType.RRDConflict: return new  RRDConflictRecord();
                case BiffRecordType.RRDDefName: return new  RRDDefNameRecord();
                case BiffRecordType.RRDHead: return new  RRDHeadRecord();
                case BiffRecordType.RRDInfo: return new  RRDInfoRecord();
                case BiffRecordType.RRDInsDel: return new  RRDInsDelRecord();
                case BiffRecordType.RRDInsDelBegin: return new  RRDInsDelBeginRecord();
                case BiffRecordType.RRDInsDelEnd: return new  RRDInsDelEndRecord();
                case BiffRecordType.RRDMove: return new  RRDMoveRecord();
                case BiffRecordType.RRDMoveBegin: return new  RRDMoveBeginRecord();
                case BiffRecordType.RRDMoveEnd: return new  RRDMoveEndRecord();
                case BiffRecordType.RRDRenSheet: return new  RRDRenSheetRecord();
                case BiffRecordType.RRDRstEtxp: return new  RRDRstEtxpRecord();
                case BiffRecordType.RRDTQSIF: return new  RRDTQSIFRecord();
                case BiffRecordType.RRDUserView: return new  RRDUserViewRecord();
                case BiffRecordType.RRFormat: return new  RRFormatRecord();
                case BiffRecordType.RRInsertSh: return new  RRInsertShRecord();
                case BiffRecordType.RRSort: return new  RRSortRecord();
                case BiffRecordType.SeriesList: return new  SeriesListRecord();
                case BiffRecordType.ShapePropsStream: return new  ShapePropsStreamRecord();
                case BiffRecordType.StartBlock: return new  StartBlockRecord();
                case BiffRecordType.StartObject: return new  StartObjectRecord();
                case BiffRecordType.SxBool: return new  SxBoolRecord();
                case BiffRecordType.SXDBB: return new  SXDBBRecord();
                case BiffRecordType.SXDtr: return new  SXDtrRecord();
                case BiffRecordType.SxErr: return new  SxErrRecord();
                case BiffRecordType.SXFDB: return new  SXFDBRecord();
                case BiffRecordType.SXInt: return new  SXIntRecord();
                case BiffRecordType.SxIsxoper: return new  SxIsxoperRecord();
                case BiffRecordType.SxNil: return new  SxNilRecord();
                case BiffRecordType.SXNum: return new  SXNumRecord();
                case BiffRecordType.SXRng: return new  SXRngRecord();
                case BiffRecordType.Sync: return new  SyncRecord();
                case BiffRecordType.TextPropsStream: return new  TextPropsStreamRecord();
                case BiffRecordType.UsrChk: return new  UsrChkRecord();
                case BiffRecordType.UsrExcl: return new  UsrExclRecord();
                case BiffRecordType.UsrInfo: return new  UsrInfoRecord();

                case BiffRecordType.Bar:
                    return new ChartBarRecord();
                case BiffRecordType.Line:
                    return new ChartLineRecord();
                case BiffRecordType.LineFormat:
                    return new LineFormatRecord();


                case BiffRecordType.SIIndex:
                    return new SeriesIndexRecord();
                case BiffRecordType.AxesUsed:
                    return new ChartUsedAxesSetsRecord();
                case BiffRecordType.Units:
                    return new ChartUnitsRecord();
                case BiffRecordType.Chart3DBarShape:
                    return new Chart3DDataFormatRecord();
                case BiffRecordType.Area:
                    return new ChartAreaRecord();
                case BiffRecordType.AreaFormat:
                    return new ChartAreaFormatRecord();
                case BiffRecordType.AttachedLabel:
                    return new ChartAttachedLabelRecord();
                case BiffRecordType.AxisParent:
                    return new AxisParentRecord();
                case BiffRecordType.Axis:
                    return new ChartAxisRecord();
                case BiffRecordType.AxisLine:
                    return new ChartAxisLineRecord();
                case BiffRecordType.Begin:
                    return new ChartBeginRecord();
                case BiffRecordType.Chart:
                    return new ChartChartRecord();
                case BiffRecordType.Chart3d:
                    return new ChartChart3DRecord();
                case BiffRecordType.DataFormat:
                    return new ChartDataFormatRecord();
                case BiffRecordType.DefaultText:
                    return new ChartDefaultTextRecord();
                case BiffRecordType.DropBar:
                    return new ChartDropBarRecord();
                case BiffRecordType.End:
                    return new ChartEndRecord();
                case BiffRecordType.GelFrame:
                    return new GelFrameRecord();
                case BiffRecordType.FontX:
                    return new ChartFontRecord();
                case BiffRecordType.ChartFormat:
                    return new ChartFormatRecord();
                case BiffRecordType.AlRuns:
                    return new ChartFormatRunsRecord();
                case BiffRecordType.Frame:
                    return new ChartFrameRecord();
                case BiffRecordType.Pos:
                    return new ChartFramePosRecord();
                    //    case BiffRecordType.LabelRange:
                    //      return new ChartLabelRange();
                    // case BiffRecordType.ChartLabelRange2:
                    //    return new ChartLabelRange2();
                case BiffRecordType.Legend:
                    return new ChartLegendRecord();
                case BiffRecordType.MarkerFormat:
                    return new ChartMarkerFormatRecord();
                case BiffRecordType.ObjectLink:
                    return new ChartObjectLinkRecord();
                case BiffRecordType.Pie:
                    return new ChartPieRecord();
                case BiffRecordType.PieFormat:
                    return new ChartPieFormatRecord();
                case BiffRecordType.PlotGrowth:
                    return new ChartPlotGrowthRecord();
                    // case BiffRecordType.Properties:
                    //    return new ChartProperties();
                case BiffRecordType.RadarArea:
                    return new ChartRadarAreaRecord();
                case BiffRecordType.Radar:
                    return new ChartRadarLineRecord();
                case BiffRecordType.Scatter:
                    return new ChartScatterRecord();
                case BiffRecordType.Text:
                    return new ChartTextRecord();
                case BiffRecordType.Tick:
                    return new ChartTickRecord();
                case BiffRecordType.ValueRange:
                    return new ChartValueRangeRecord();
                case BiffRecordType.AutoFilter12:
                    return new AutoFilter12Record();
                case BiffRecordType.AxcExt:
                    return new AxcExtRecord();
                case BiffRecordType.BopPop:
                    return new BopPopRecord();
                case BiffRecordType.BRAI: return new  BRAIRecord();
                case BiffRecordType.CatSerRange: return new  CatSerRangeRecord();
                case BiffRecordType.CellWatch: return new  CellWatchRecord();
                case BiffRecordType.CF: return new  CFRecord();
                case BiffRecordType.CF12: return new  CF12Record();
                case BiffRecordType.CFEx: return new  CFExRecord();
                case BiffRecordType.CondFmt: return new  CondFmtRecord();
                case BiffRecordType.CondFmt12: return new  CondFmt12Record();
                case BiffRecordType.ContinueFrt: return new  ContinueFrtRecord();
                case BiffRecordType.ContinueFrt11: return new  ContinueFrt11Record();
                case BiffRecordType.ContinueFrt12: return new  ContinueFrt12Record();
                case BiffRecordType.CrErr: return new  CrErrRecord();
                case BiffRecordType.CRN: return new  CRNRecord();
                case BiffRecordType.CrtLine: return new  CrtLineRecord();
                case BiffRecordType.DataLabExt: return new  DataLabExtRecord();
                case BiffRecordType.DataLabExtContents: return new  DataLabExtContentsRecord();
                case BiffRecordType.DbOrParamQry: return new  DbOrParamQryRecord();
                case BiffRecordType.DBQueryExt: return new  DBQueryExtRecord();
                case BiffRecordType.DCon: return new  DConRecord();
                case BiffRecordType.DConBin: return new  DConBinRecord();
                case BiffRecordType.DConn: return new  DConnRecord();
                case BiffRecordType.DConName: return new  DConNameRecord();
                case BiffRecordType.DConRef: return new  DConRefRecord();
                    // case BiffRecordType.DefinedName: return new  DefinedNameRecord(;
                case BiffRecordType.DocRoute: return new  DocRouteRecord();
                case BiffRecordType.DropDownObjIds: return new  DropDownObjIdsRecord();
                case BiffRecordType.DVal: return new  DValRecord();
                case BiffRecordType.DXF: return new  DXFRecord();
                case BiffRecordType.ExtString: return new  ExtStringRecord();
                case BiffRecordType.FeatHdr11: return new  FeatHdr11Record();
                case BiffRecordType.Feature11: return new  Feature11Record();
                case BiffRecordType.Feature12: return new  Feature12Record();
                case BiffRecordType.FileSharing: return new  FileSharingRecord();
                case BiffRecordType.FnGroupName: return new  FnGroupNameRecord();
                case BiffRecordType.HFPicture: return new  HFPictureRecord();
                case BiffRecordType.HLink: return new  HLinkRecord();
                case BiffRecordType.HLinkTooltip: return new  HLinkTooltipRecord();
                case BiffRecordType.HorizontalPageBreaks: return new  HorizontalPageBreaksRecord();
                case BiffRecordType.IFmtRecord: return new  IFmtRecordRecord();
                case BiffRecordType.LPr: return new  LPrRecord();
                case BiffRecordType.MDB: return new  MDBRecord();
                case BiffRecordType.MDTInfo: return new  MDTInfoRecord();
                case BiffRecordType.MDXKPI: return new  MDXKPIRecord();
                case BiffRecordType.MDXProp: return new  MDXPropRecord();
                case BiffRecordType.MDXSet: return new  MDXSetRecord();
                case BiffRecordType.MDXStr: return new  MDXStrRecord();
                case BiffRecordType.MDXTuple: return new  MDXTupleRecord();
                case BiffRecordType.NameCmt: return new  NameCmtRecord();
                case BiffRecordType.NameFnGrp12: return new  NameFnGrp12Record();
                case BiffRecordType.NamePublish: return new  NamePublishRecord();
                case BiffRecordType.OleDbConn: return new  OleDbConnRecord();
                case BiffRecordType.OleObjectSize: return new  OleObjectSizeRecord();
                case BiffRecordType.PicF: return new  PicFRecord();
                case BiffRecordType.PlotArea: return new  PlotAreaRecord();
                case BiffRecordType.QsiSXTag: return new  QsiSXTagRecord();
                case BiffRecordType.RealTimeData: return new  RealTimeDataRecord();
                case BiffRecordType.RecipName: return new  RecipNameRecord();
                case BiffRecordType.SBaseRef: return new  SBaseRefRecord();
                case BiffRecordType.SCENARIO: return new  SCENARIORecord();
                case BiffRecordType.ScenarioProtect: return new  ScenarioProtectRecord();
                case BiffRecordType.ScenMan: return new  ScenManRecord();
                case BiffRecordType.SerAuxErrBar: return new  SerAuxErrBarRecord();
                case BiffRecordType.SerAuxTrend: return new  SerAuxTrendRecord();
                case BiffRecordType.SerFmt: return new  SerFmtRecord();
                case BiffRecordType.Series: return new  SeriesRecord();
                case BiffRecordType.SeriesText: return new  SeriesTextRecord();
                case BiffRecordType.SerParent: return new  SerParentRecord();
                case BiffRecordType.SerToCrt: return new  SerToCrtRecord();
                case BiffRecordType.ShtProps: return new  ShtPropsRecord();
                case BiffRecordType.SortData: return new  SortDataRecord();
                case BiffRecordType.Surf: return new  SurfRecord();
                case BiffRecordType.SXAddl: return new  SXAddlRecord(); 

                case BiffRecordType.SXDB: return new  SXDBRecord();
                case BiffRecordType.SXDBEx: return new  SXDBExRecord();
                case BiffRecordType.SXDI: return new  SXDIRecord();
                case BiffRecordType.SxDXF: return new  SxDXFRecord();
                case BiffRecordType.SXEx: return new  SXExRecord();
                case BiffRecordType.SXFDBType: return new  SXFDBTypeRecord();
                case BiffRecordType.SxFilt: return new  SxFiltRecord();
                case BiffRecordType.SxFmla: return new  SxFmlaRecord();
                case BiffRecordType.SxFormat: return new  SxFormatRecord();
                case BiffRecordType.SXFormula: return new  SXFormulaRecord();
                case BiffRecordType.SxItm: return new  SxItmRecord();
                case BiffRecordType.SxIvd: return new  SxIvdRecord();
                case BiffRecordType.SXLI: return new  SXLIRecord();
                case BiffRecordType.SxName: return new  SxNameRecord();
                case BiffRecordType.SXPair: return new  SXPairRecord();
                case BiffRecordType.SXPI: return new  SXPIRecord();
                case BiffRecordType.SXPIEx: return new  SXPIExRecord();
                case BiffRecordType.SxRule: return new  SxRuleRecord(); 

                case BiffRecordType.SxSelect: return new  SxSelectRecord();
                case BiffRecordType.SXStreamID: return new  SxStreamIdRecord();
                case BiffRecordType.SXString: return new  SXStringRecord();
                case BiffRecordType.SXTbl: return new  SXTblRecord();
                case BiffRecordType.SxTbpg: return new  SxTbpgRecord();
                case BiffRecordType.SXTBRGIITM: return new  SXTBRGIITMRecord();
                case BiffRecordType.SXTH: return new  SXTHRecord();
                case BiffRecordType.SXViewEx9: return new  SXViewEx9Record();
                case BiffRecordType.SXViewLink: return new  SXViewLinkRecord();
                case BiffRecordType.SXVS: return new  SXVSRecord();
                case BiffRecordType.TxO: return new  TxORecord();
                case BiffRecordType.TxtQry: return new  TxtQryRecord();
                case BiffRecordType.UserBView: return new  UserBViewRecord();
                case BiffRecordType.UserSViewBegin: return new  UserSViewBeginRecord();
                    //case BiffRecordType.UserSViewBegin_Chart: return new  UserSViewBegin_ChartRecord(;
                case BiffRecordType.UserSViewEnd: return new  UserSViewEndRecord();
                case BiffRecordType.VerticalPageBreaks: return new  VerticalPageBreaksRecord();
                case BiffRecordType.WebPub: return new  WebPubRecord();
                case BiffRecordType.WOpt: return new  WOptRecord();
                case BiffRecordType.WriteProtect: return new  WriteProtectRecord();
                case BiffRecordType.XCT: return new  XCTRecord();
                case BiffRecordType.YMult: return new  YMultRecord();
                case (BiffRecordType)52:
                    return new Record52();

#if DEBUG
                    throw new NotSupportedException();
#else
                    throw new NotSupportedException();//\\   return new UnhandledRecord(type);
#endif

                default:
                    Debug.WriteLine("PROBLEM WITH " + type + " " + string.Format("{0:X}", type));
                    throw new NotSupportedException();
                    /*
                                    throw new NotImplementedException(string.Format(" id = {0:x}", type));
                */
            }
        }
    }
}